<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
    <meta name="author" content="">
    <title></title>
    <% include("../inc/list_css.html"){}%>
</head>
<body>
<div class="ibox ">
    <div class="ibox-title">
        <div class="pull-left mbx navbar_title">
            <span>权限管理 </span>
            <span class="line">/</span>
            动作管理
        </div>
    </div>

    <div class="ibox-content">
        <div class="wrapper wrapper-content">
            <div class="row">
                <div class="col-md-12">
                    <div class="btn-group margin-vertical-4_0">
                        <button class="hive-btn-md-large hive-btn-primary" id="add">
                            <i class="icon-add" aria-hidden="true"></i>&nbsp;添加动作
                        </button>
                    </div>
                    <table data-toggle="table " id="table" data-show-export="true" class=" table-striped table-no-bordered fixed-table-container table-row-border-color table-hovered table-hover">
                        <thead class="table-header">
                        <tr>
                            <th data-field="name" data-formatter="nameFormatter">动作名称</th>
                            <th data-field="resourceName">资源名称</th>
                            <th data-field="createDate">创建日期</th>
                            <th data-field="head" data-formatter="opFormatter" data-halign="center"  data-align="center" data-width="120">操作</th>
                        </tr>
                        </thead>
                    </table>

                </div>
            </div>
        </div>
    </div>
</div>


<% include("../inc/list_js.html"){}%>
<script>

    function opFormatter(value, row, index){
        var html = '<a href="javascript:void(0)" class="icon-edit hive_icon color_normal" onclick="edit(\''+row.id+'\');" data-toggle="tooltip" data-placement="top" title="编辑"></a>';
        html += '<a href="javascript:void(0)" class="icon-delete hive_icon color_danger" onclick="del(\''+row.id+'\');" data-toggle="tooltip" data-placement="top" title="删除"></a>';
        html += '<a href="javascript:void(0)" class="icon-copy-link hive_icon color_normal" onclick="copyToClipboard(\''+row.id+'\');" data-toggle="tooltip" data-placement="top" title="复制id"></a>';
        html += '<textarea id=\''+row.id+'\' style="display: none;" value=\''+row.id+'\' >'+row.id+'</textarea>';
        return html;
    }

    function nameFormatter(value, row, index) {
        return row.resourceName+"("+row.name+")";//资源名+动作名
    }

    function del(v) {
        parent.layer.confirm('您确定要删除吗?', {
            shade: [0.3,'#fff'],//0.1透明度的白色背景
            btn: ['是','否'] //按钮e.state == "fail"
        }, function(){
            $.post('delete',{"ids":v},function (e) {
                if(e.state == "fail"){
                    parent.layer.msg(e.info);
                }else{
                    parent.layer.msg("删除成功!");
                    $('#table').bootstrapTable('refresh');
                }
            })
        });

    }

    function copyToClipboard(elementId) {
        // 创建元素用于复制
        var aux = document.createElement("input");

        // 获取复制内容
        var content = document.getElementById(elementId).innerHTML || document.getElementById(elementId).value;

        // 设置元素内容
        aux.setAttribute("value", content);

        // 将元素插入页面进行调用
        document.body.appendChild(aux);

        // 复制内容
        aux.select();

        // 将内容复制到剪贴板
        document.execCommand("copy");

        // 删除创建元素
        document.body.removeChild(aux);
        layer.msg("复制成功");
    }

    function edit(v) {
        location.href = "edit?id="+v;
    }
    /**
     * 加载页面数据
     * */
    (function () {

        $('#table').bootstrapTable({
            url: "ajaxlist",
            dataType: 'json',
            contentType: 'application/json',
            search: true,
            searchAlign: 'right',
            pagination: true,
            showRefresh: true,
            pageSize: 20,
            showToggle: false,//是否显示card/table切换按钮
            showColumns: true,//是否显示内容列下拉框
            pageList: [20, 50, 100],
            iconSize: 'outline',
            toolbar: '#eventsToolbar',
            paginationHAlign: 'right', //right, left
            paginationVAlign: 'bottom',
            icons: {
                refresh: 'icon-refresh',
                toggle: 'glyphicon-list-alt',
                columns: 'icon-select',
                export: 'icon-export'
            },

            formatNoMatches: function () { //判断有无数据
                var imghtml = '<div class="flexed_column content_center content_alignCenter padding-20"><img src="https://static.9hive.cn/global/img/nodata.png" class="no_data"/><span class="font-size-16">暂无数据</span></div>';
                return imghtml;
            },
            formatLoadingMessage: function () {  //数据加载中样式
                return ' <div id="loading"><div id="loading-center">' +
                    '<div id="loading-center-absolute"><div class="object" id="object_one">' +
                    '</div><div class="object" id="object_two"></div><div class="object" id="object_three">' +
                    '</div><div class="object" id="object_four"></div></div></div>努力加载中...</div>'
            },
        });

        $('#add').on('click', function (e) {
            location.href = 'add';
        });

        $(".wrapper").tooltip({selector: "[data-toggle=tooltip]", container: "body"});

    })();
</script>
</body>
</html>